package com.oa.dao.organization.hibernate;

import java.util.ArrayList;
import java.util.List;

import com.oa.dao.hibernate.GenericDaoHibernate;
import com.oa.dao.organization.OrganizationDao;
import com.oa.model.Organization;

public class OrganizationDaoHibernate extends GenericDaoHibernate<Organization, Long> implements OrganizationDao{

	public OrganizationDaoHibernate() {
		super(Organization.class);
	}
	
	public List<Organization> findOrganizationsByParentOrgId(Long parentOrgId) {
		List<Organization> orgList = new ArrayList<Organization> ();
		if (parentOrgId == 0) {
			orgList = (List<Organization>) this.getHibernateTemplate().find("from Organization org where org.parentO is null");
		} else {
			orgList = (List<Organization>) this.getHibernateTemplate().find("from Organization org where org.parentO.id = ?", parentOrgId);
		}
		return orgList;
		
	}
}
